<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2023/4/12
 * Time: 15:44
 */

namespace App\Rep;


use App\Models\MaterialType;

class MaterialTypeRep
{
    /**
     * 获取供应商列表
     * @param $params
     */
    public function getMaterialTypeListRep($params){
        return MaterialType::Search($params)
            ->orderBy('id','desc')
            ->paginate($params['per_page']??100);
    }

    /**
     * 添加供应商
     * @param $params
     */
    public function createMaterialTypeRep($params){
        if(isset($params['id']) && !empty($params['id'])){
            $model = MaterialType::where('id',$params['id'])->first();
        }else{
            $model = MaterialType::where('name',$params['name'])->first();
            if($model){
                return ['code'=>1015,'data'=>[],'msg'=>'该名称已存在'];
            }
            $model = new MaterialType();
        }
        $model->name = $params['name'];
        $model->save();
        return ['code'=>0,'data'=>$model,'msg'=>'success'];
    }

    /**
     * 删除供应商
     * @param $params
     */
    public function delMaterialTypeRep($params){
        $model = MaterialType::where('id',$params['id'])->first();
        $model->is_del = $params['is_del'];
        $model->save();
        return ['code'=>0,'data'=>$model,'msg'=>'success'];
    }
}